package com.stock;

import com.kevin.entity.Stock;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class StockParser implements Parser{
	
/**
{
    "column": [
        "symbol",
        "name",
        "hasexist"
    ],
    "data": [
        [
            "SZ000016",
            "深康佳A",
            "false"
        ],
        [
            "SZ000720",
            "新能泰山",
            "false"
        ]
    ],
    "count": 1496
}
 */
	
	@Override
	public List<Stock> parse(String text) {
//		System.out.println("json:"+json);
		Map<String,Object> map = JsonUtils.json2obj(text, Map.class);
		List column = (List)map.get("column");
		List<List<String>> data =  (List)map.get("data");
		BigDecimal count = new BigDecimal(map.get("count").toString());
//		System.out.println("column:"+column);
//		System.out.println("data:"+data);
//		System.out.println("count:"+count);
		List<Stock> list=new ArrayList<Stock>();
		for(List<String> d:data){
			Stock s=new Stock();
			s.setSymbol(d.get(0));
			s.setName(d.get(1));
			list.add(s);
		}
		return list;
	}

}
